package socket;

import jdk.nashorn.internal.parser.JSONParser;

import java.io.*;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zzy on 2018/1/9.
 */
public class SocketClientOne {

    public static int count=0;
    public static void main(String[] args) {
        try {
            for(int i=0;i<100;i++) {
                //1、创建客户端socket，指定服务器地址和端口
                Socket socket = new Socket("localhost", 9999);
                //2、获取输出流想服务器端发送信息
                OutputStream outputStream = socket.getOutputStream();
                PrintWriter pw = new PrintWriter(outputStream);//将输出流包装为打印流
                Map param = new HashMap();
                param.put("username", "zzy");
                param.put("password", "123");
                pw.write(String.valueOf(i));
                pw.flush();
                socket.shutdownOutput();
                //3、接收服务器端相应
                InputStream inputStream = socket.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                System.out.println("我是客户端"+i+"，服务器说:" + reader.readLine());

                socket.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
